package com.bian.plugin.boot.controller;

import com.bian.plugin.boot.service.PluginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author bian
 * @since 1.0
 * 2021/2/22
 */
@Api(tags = "插件服务")
@RestController
public class PluginController {

    @Autowired
    private PluginService pluginService;


    @GetMapping("/load")
    @ApiOperation(value = "加载jar")
    @ApiImplicitParam(name = "jarPath", value = "jar路径", paramType = "query")
    public String load(@RequestParam String jarPath) {
        pluginService.load(jarPath);
        return "load:" + jarPath;
    }

    @GetMapping("/unload")
    @ApiOperation(value = "卸载jar")
    @ApiImplicitParam(name = "pluginName", value = "插件名", paramType = "query")
    public String unload(@RequestParam String pluginName) {
        pluginService.unload(pluginName);
        return "unload:" + pluginName;
    }

    @GetMapping("/register")
    @ApiOperation(value = "注册jar")
    @ApiImplicitParam(name = "pluginName", value = "插件名", paramType = "query")
    public String register(@RequestParam String pluginName) {
        pluginService.register(pluginName);
        return "register:" + pluginName;
    }

    @GetMapping("/unregister")
    @ApiOperation(value = "反注册jar")
    @ApiImplicitParam(name = "pluginName", value = "插件名", paramType = "query")
    public String unregister(@RequestParam String pluginName) {
        pluginService.unregister(pluginName);
        return "unregister:" + pluginName;
    }

    @GetMapping("/test")
    public String test(String testInfo) {
        return "test:" + testInfo;
    }
}
